//
//  RHApplicationListCell.m
//  RuiHeAppApp
//
//  Created by Jun on 2023/7/25.
//

#import "RHApplicationListCell.h"
#import "RHTools.h"

@interface RHApplicationListCell()

@property (nonatomic ,strong) UIImageView *iconView;

@property (nonatomic ,strong) UIImageView *stateBgView;

@property (nonatomic ,strong) QMUIButton *stateBtn;

@property (nonatomic ,strong) QMUILabel *titleLab;

@property (nonatomic ,strong) QMUILabel *contentLab;

@property (nonatomic ,strong) QMUILabel *timeLab;

@end

@implementation RHApplicationListCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self){
        [self setupUI];
    }
    return self;
}
-(void)setModel:(RHApplicationDetailModel *)model
{
    _model = model;
//    [_titleLab setText:[RHTools getRoleContentWithType:(UserRoleType)[model.partnerType integerValue]]];
    _titleLab.text = @"";
    NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
    formatter.dateFormat = @"yyyy-MM-dd HH:mm:ss";
    NSDate *date = [NSDate dateWithTimeIntervalSince1970:model.createTimestamp/1000];
    NSString *timeStr = [formatter stringFromDate:date];
    [_timeLab setText:[NSString stringWithFormat:@"Date: %@",model.createTime]];
    
    switch (model.auditStatus) {
            //未审核
        case AuditStatusUnaudited:
            {
                [_iconView setImage:[UIImage imageNamed:@"application_icon_02"]];
                [_stateBgView setImage:[UIImage imageNamed:@"state_bg_02"]];
                [_stateBtn setImage:[UIImage imageNamed:@"state_mark_02"] forState:UIControlStateNormal];
                [_stateBtn setTitle:@"unaudited" forState:UIControlStateNormal];
                [_stateBtn setTitleColor:kCOLOR_HEX(@"FFB548") forState:UIControlStateNormal];
                [_contentLab setText:@"Application Des Application Des"];
                
            }
            break;
            //审核通过
        case AuditStatusApproved:
            {
                [_iconView setImage:[UIImage imageNamed:@"application_icon_01"]];
                [_stateBgView setImage:[UIImage imageNamed:@"state_bg_01"]];
                [_stateBtn setImage:[UIImage imageNamed:@"state_mark_01"] forState:UIControlStateNormal];
                [_stateBtn setTitle:@"pass" forState:UIControlStateNormal];
                [_stateBtn setTitleColor:kCOLOR_HEX(@"56C271") forState:UIControlStateNormal];
                [_contentLab setText:@"Application Des Application Des"];
               
            }
            break;
            //驳回
        case AuditStatusReject:
            {
                [_iconView setImage:[UIImage imageNamed:@"application_icon_03"]];
                [_stateBgView setImage:[UIImage imageNamed:@"state_bg_03"]];
                [_stateBtn setImage:[UIImage imageNamed:@"state_mark_03"] forState:UIControlStateNormal];
                [_stateBtn setTitle:@"rejiect" forState:UIControlStateNormal];
                [_stateBtn setTitleColor:kCOLOR_HEX(@"FF7168") forState:UIControlStateNormal];
                [_contentLab setText:@"Application Des Application Des"];
               
            }
            break;
        default:
            break;
    }
    
    kWeakSelf;
    [_stateBtn sizeToFit];
    [_stateBtn mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.offset(weakSelf.stateBtn.width+10);
    }];
}


- (void)setupUI{
    [self setBackgroundColor:CFTabViewBgColor];
    [self.contentView setBackgroundColor:CFTabViewBgColor];
    
    UIView *bgView = [[UIView alloc] init];
    [bgView setBackgroundColor:UIColor.whiteColor];
    [bgView.layer setCornerRadius:8];
    [self.contentView addSubview:bgView];
    
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_offset(10);
        make.left.mas_offset(15);
        make.right.mas_offset(-15);
        make.bottom.mas_offset(-5);
        make.height.mas_equalTo(161);
    }];
    
    
    _iconView = [[UIImageView alloc] init];
    [_iconView.layer setCornerRadius:4];
    [bgView addSubview:_iconView];
    
    _titleLab = [[QMUILabel alloc] init];
    [_titleLab setTextAlignment:NSTextAlignmentLeft];
    [_titleLab setFont:[UIFont systemFontOfSize:15]];
    [_titleLab setTextColor:kCOLOR_HEX(@"3F4443")];
    [bgView addSubview:_titleLab];
    
    _contentLab = [[QMUILabel alloc] init];
    [_contentLab setTextAlignment:NSTextAlignmentLeft];
    [_contentLab setFont:[UIFont systemFontOfSize:13]];
    [_contentLab setTextColor:[kCOLOR_HEX(@"3F4443") colorWithAlphaComponent:0.5]];
    [bgView addSubview:_contentLab];
    
    UIView *lineV = [[UIView alloc] init];
    [lineV setBackgroundColor:CFCellLineColor];
    [bgView addSubview:lineV];
    
    _timeLab = [[QMUILabel alloc] init];
    [_timeLab setTextAlignment:NSTextAlignmentLeft];
    [_timeLab setFont:[UIFont systemFontOfSize:13]];
    [_timeLab setTextColor:[kCOLOR_HEX(@"3F4443") colorWithAlphaComponent:0.5]];
    [bgView addSubview:_timeLab];
    
    QMUIButton *seeBtn = [QMUIButton buttonWithType:UIButtonTypeCustom];
    [seeBtn setTitle:@"view details" forState:UIControlStateNormal];
    [seeBtn setTitleColor:CFMainColor forState:UIControlStateNormal];
    [seeBtn setImage:[UIImage imageNamed:@"details_arrow"] forState:UIControlStateNormal];
    [seeBtn.titleLabel setFont:[UIFont systemFontOfSize:13]];
    [seeBtn setImagePosition:QMUIButtonImagePositionRight];
    [seeBtn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentRight];
    [bgView addSubview:seeBtn];
    
    _stateBgView = [[UIImageView alloc] init];
    [bgView addSubview:_stateBgView];
    
    
    _stateBtn = [QMUIButton buttonWithType:UIButtonTypeCustom];
    [_stateBtn setImagePosition:QMUIButtonImagePositionLeft];
    [_stateBtn.titleLabel setFont:[UIFont systemFontOfSize:11]];
    [_stateBtn setSpacingBetweenImageAndTitle:5];
    [_stateBgView addSubview:_stateBtn];
    

    kWeakSelf;
    [_stateBgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.offset(28);
        make.right.top.mas_offset(0);
    }];
    
    [_stateBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.insets(UIEdgeInsetsMake(0, 8, 0, 5));
    }];
    
    [_iconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(48, 48));
        make.left.mas_offset(15);
        make.top.mas_offset(30);
    }];
    
    [_titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.iconView.mas_right).offset(10);
        make.top.equalTo(weakSelf.iconView);
        make.right.mas_offset(-15);
        make.height.mas_equalTo(20);
    }];
    
    [_contentLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.titleLab);
        make.top.equalTo(weakSelf.titleLab.mas_bottom).offset(5);
        make.right.equalTo(weakSelf.titleLab);
        make.height.mas_equalTo(20);
    }];
    
    [lineV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(15);
        make.right.mas_offset(-15);
        make.height.mas_equalTo(1);
        make.bottom.mas_offset(-50);
        
    }];
    
    [_timeLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.iconView);
        make.top.equalTo(lineV.mas_bottom);
        make.bottom.mas_offset(0);
        make.width.mas_equalTo(200);
    }];
    
    [seeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_offset(-15);
        make.top.equalTo(lineV.mas_bottom);
        make.bottom.mas_offset(0);
        make.width.mas_equalTo(100);
    }];
    
    
    [_iconView setImage:[UIImage imageNamed:@"application_icon_01"]];
    [_stateBgView setImage:[UIImage imageNamed:@"state_bg_01"]];
    [_stateBtn setImage:[UIImage imageNamed:@"state_mark_01"] forState:UIControlStateNormal];
    [_stateBtn setTitle:@"pass" forState:UIControlStateNormal];
    [_stateBtn setTitleColor:CFMainColor forState:UIControlStateNormal];
    [_titleLab setText:@"Application"];
    [_contentLab setText:@"Application Des Application Des"];
    [_timeLab setText:[NSString stringWithFormat:@"Date: %@",@"2023-07-25"]];

}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
